﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using StockManagement.ViewModels;

namespace StockManagement.Views
{
    /// <summary>
    /// Interaction logic for MaterialGrid.xaml
    /// </summary>
    public partial class MaterialGrid : Frame
    {
        MaterialGridViewModel _matgridVM;
        public MaterialGrid()
        {
            InitializeComponent();
            DataContextChanged += new DependencyPropertyChangedEventHandler(MaterialGrid_DataContextChanged);
        }

        void MaterialGrid_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue == null)
                return;
            var matStockVM = e.NewValue as MaterialGridViewModel;
            if (matStockVM == null)
                return;
            _matgridVM = matStockVM;
            _mainGrid.DataContext = matStockVM;
            //if (_matgridVM.AllMaterialCollection.Count != _matgridVM.MaterialCollection.Count)
            //    rdAllMat.IsChecked = true;
        }

        //private void RadioButton_Checked(object sender, RoutedEventArgs e)
        //{
        //    if (_matgridVM == null)
        //        return;

        //    switch (((RadioButton)sender).Uid)
        //    {
        //        case "rdall":
        //            var coll = _matgridVM.AllMaterialCollection.AsEnumerable();
        //            _matgridVM.MaterialCollection = new System.Collections.ObjectModel.ObservableCollection<MaterialViewModel>(coll);
        //            break;
        //        case "rdmanf":
        //            coll = _matgridVM.AllMaterialCollection.Where(p => p.MaterialType == Helper.EnumMaterialType.Manufacturing);
        //            _matgridVM.MaterialCollection = new System.Collections.ObjectModel.ObservableCollection<MaterialViewModel>(coll);
        //            break;
        //        case "rddprod":
        //            coll = _matgridVM.AllMaterialCollection.Where(p => p.MaterialType == Helper.EnumMaterialType.Trading);
        //            _matgridVM.MaterialCollection = new System.Collections.ObjectModel.ObservableCollection<MaterialViewModel>(coll);
        //            break;
        //        default:
        //            _matgridVM.MaterialCollection = new System.Collections.ObjectModel.ObservableCollection<MaterialViewModel>();
        //            break;
        //    }

        //    switch (rdmanf.IsChecked)  
        //    {
        //        case true:
        //            colPurchaser.Visibility = System.Windows.Visibility.Collapsed;                   
        //            break;
        //        default:
        //            colPurchaser.Visibility = System.Windows.Visibility.Visible;
        //            break;
        //    }
        //}
    }
}
